import 'package:flutter_benchu/utils/commonPkg.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import './widgets/app_bar.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin {
  List pageData = [
    {'name': '组件展示', 'router': Routes.getwidgetDemo,'bgColor':Colors.deepOrangeAccent},
    {'name': '网页跳转', 'router': Routes.routerDemo,'bgColor':Colors.green},
    {'name': '切换语言', 'router': Routes.languageDemo,'bgColor':Colors.blue},
    {'name': '屏幕适配', 'router': Routes.aptDemo,'bgColor':LightColors.red},
    {'name': '请求接口', 'router': Routes.apiDemo,'bgColor':Colors.transparent},
    {'name': '事件监听', 'router': Routes.eventDemo,'bgColor':Colors.deepPurpleAccent},
    {'name': '本地缓存', 'router': Routes.cacheDemo,'bgColor':Colors.orangeAccent},
    {'name': 'webview', 'router': Routes.webView,'bgColor':Colors.lightBlueAccent},
    {'name': '原生交互', 'router': Routes.sendNativeDemo,'bgColor':Colors.green},
  ];

  // 缓存配置开启
  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appBarWidget(context),
      body: EasyRefresh(
          header: PhoenixHeader(),  //头部刷新
          bottomBouncing:false,     //底部回弹效果
          onRefresh: () async {
            //下拉请求新数据
          },
          //需要上下拉刷新的组件 这里是CustomScrollView
          child: ListView(
            padding: EdgeInsets.fromLTRB(0, 24.w, 0, 0),
            children: <Widget>[
              ...pageData.map((item) {
                return ButtonItem(
                  title: item['name'],
                  bgColor: item['bgColor'],
                  onPressed: () {
                    appRouter.navTo(context, item['router']);
                    Log.v(item['name']);
                  },
                );
              }),
            ],
          )),
    );
  }
}
